import 'package:boss/models/material.dart' as material;
import 'package:boss/models/store_menu.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';

class ClassificationDetailProvider extends ChangeNotifier {
  StoreMenu menu;

  ClassificationDetailProvider({StoreMenu menu}) {
    this.menu = menu ?? StoreMenu.fromJson({});
  }

  bool get isUpdateStoreMenu {
    return menu.menuId != null;
  }

  setMenu(StoreMenu menu) {
    this.menu = menu;
    notifyListeners();
  }

  setMaterials(List<material.Material> materials) {
    menu.commodityMeterialList = materials;
    notifyListeners();
  }

  deleteMaterial(material.Material data) {
    menu.commodityMeterialList.remove(data);
    notifyListeners();
  }

  toggleIsPackage(bool flag) {
    if (menu.commodityList.isNotEmpty) {
      toast('菜品分类下有菜品，无法修改套餐分类');
      return;
    }

    menu.isPackages = flag ? 1 : 0;
    notifyListeners();
  }

  setImage(String imagePath) {
    menu.images = imagePath;
    notifyListeners();
  }
}
